<template>
	<view class="p15">
		<uni-section title="求职意向" type="line"></uni-section>
		<uni-forms class="form" ref="form" :modelValue="form" label-position="left" label-width="80px">
			<uni-forms-item label="职位" required>
				<uni-easyinput v-model="form.position" placeholder="请输入职位" />
			</uni-forms-item>
			<uni-forms-item label="地点" required>
				<uni-easyinput v-model="form.address" placeholder="请输入地点" />
			</uni-forms-item>
			<uni-forms-item label="薪资类型" required>
				<uni-data-checkbox v-model="form.salary_type" :localdata="scale" />
			</uni-forms-item>
			<uni-forms-item label="期望薪资" required>
				<uni-data-select v-if="form.salary_type == 1" v-model="form.salary" :localdata="year_wages"></uni-data-select>
				<uni-data-select v-else v-model="form.salary" :localdata="month_wages"></uni-data-select>
			</uni-forms-item>
<!-- 			<uni-forms-item label="个人标签">
				<view class="p8-0">
					<uni-tag text="标签" type="warning" class="mr5" />
					<uni-tag text="新增" />
				</view>
			</uni-forms-item> -->
		</uni-forms>
		<button class="default-button" @click="save()">提交</button>
	</view>
</template>

<script>
	export default {
		name:"resume_work",
		data() {
			return {
				id:0,
				resume_id:0,
				scale:[{text:'年薪',value:1},{text:'月薪',value:2}],
				year_wages:[],
				month_wages:[],
				form:{salary:1,salary_type:1},
			};
		},
		onLoad(options){
			this.month_wages = this.$func.map_arr(this.$func.month_wages)
			this.year_wages = this.$func.map_arr(this.$func.year_wages)
			
			this.id = options.id
			this.resume_id = options.resume_id
			this.onGetData()
			// api/getWorkExpect resume_id
			
			// api/addWorkExpect
			// address: "["北京市"]"
			// flag: "[""]"
			// industry: ""
			// job_type: -1
			// position: "php"
			// resume_id: "121"
			// salary: 2
			// salary_type: 1
		},
		methods: {
			onGetData(){
				let _this = this
				this.$request('/api/getWorkExpect','POST',{resume_id:_this.resume_id}).then(res => {
					_this.form = res.data ? res.data : {},
					_this.form.salary = parseInt(_this.form.salary)
				}).catch(err => {
					console.log(err)
				})
			},
			save(){
				if(!this.form.position){
					uni.showToast({title: '请输入职位',icon: 'error',duration: 2000})
					return;
				}
				if(!this.form.address){
					uni.showToast({title: '请输入地点',icon: 'error',duration: 2000})
					return;
				}
				if(!this.form.salary_type){
					uni.showToast({title: '请输入薪资类型',icon: 'error',duration: 2000})
					return;
				}
				if(!this.form.salary){
					uni.showToast({title: '请输入期望薪资',icon: 'error',duration: 2000})
					return;
				}
				let _this = this
				this.form.resume_id = this.resume_id
				let url = '/api/addWorkExpect'
				this.$request(url,'POST',this.form).then(res => {
					if(res.code != 0){
						uni.showToast({title: '保存失败',icon: 'error',duration: 2000})
						return;
					}
					uni.showToast({title: '保存成功',icon: 'success',duration: 2000})
					uni.navigateTo({
						url: "/user/resume/resume"
					});
				}).catch(err => {
					console.log(err)
				})
			}
		}
	}
</script>

<style>
</style>